home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr28 / netpag.zip / NET_PAGE.C next >
C/C++ Source or Header  |  1993-03-04  |  4KB  |  170 lines

  1. /**************************************************************************************************
  2. *
  3. *        Title:    NET_PAGE.C
  4. *        Copyright (c) April 1992, Ryu Consulting, 916/722-1939
  5. *
  6. *        This program sends a page message to the console, then returns
  7. *
  8. **************************************************************************************************/
  9.  
  10. #define    _NET_PAGE_C_
  11.  
  12. #include <stdlib.h>
  13. #include <string.h>
  14. #include <io.h>
  15. #include <rjuser.h>
  16. #include <int_14.h>
  17. #include <network.h>
  18.  
  19.  
  20. char Def_File[_MAX_DIR] = "dorinfo1.def";
  21. char User_Name[100];
  22. char Message[100];
  23. int    Door_File_Type = 0;                        // 0=DORINFOx.DEF, 1=DOOR.SYS
  24. struct
  25. {
  26.     char    *token;
  27.     int        type;
  28. } Door_Search[] =
  29. {
  30.     "dorinfo1.def",        0,
  31.     "door.sys",            1,
  32.     "",                    -1
  33. };
  34.  
  35.  
  36. /**************************************************************************************************
  37. *
  38. *    int GET_GLOBALS( void )
  39. *    Loads the COM port and user name
  40. *
  41. *    Given:
  42. *        Def_File[] = file to load from
  43. *
  44. *    Returns:
  45. *        0 if loaded, <0 if file error
  46. *
  47. **************************************************************************************************/
  48. int get_globals( void )
  49. {
  50.     char buffer[100];
  51.     int    i, handle;
  52.  
  53.     for ( i=0 ; Door_Search[i].type != -1 ; ++i )
  54.     {
  55.         if ( strcmpi(Door_Search[i].token,Def_File) == 0 )
  56.         {
  57.             Door_File_Type = Door_Search[i].type;
  58.             break;
  59.         }
  60.     }
  61.     if ( Door_Search[i].type == -1 )
  62.         return -3;
  63.     if ( (handle=dos_open(Def_File,OPEN_RO+DENY_NONE)) < 0 )
  64.         return -1;
  65.     switch ( Door_File_Type )
  66.     {
  67.         case 0:                            // DORINFO1.DEF
  68.             for ( i=0 ; i<4 ; ++i )
  69.                 fscan( handle, " %[^\xd\xa]", buffer );
  70.             _Com_Cprint_Number = buffer[3] - '1';
  71.             for ( i=0 ; i<2 ; ++i )
  72.                 fscan( handle, " %[^\xd\xa]", buffer );
  73.             fscan( handle, " %[^\xd\xa] %[^\xd\xa]", User_Name, buffer );
  74.             strmcat( User_Name, " ", buffer, NULL );
  75.             break;
  76.  
  77.         case 1:                            // DOOR.SYS
  78.             fscan( handle, " %[^\xd\xa] %[^\xd\xa]", User_Name, buffer );
  79.             _Com_Cprint_Number = buffer[0] - '1';
  80.             break;
  81.  
  82.         default:
  83.             dos_close( handle );
  84.             return -2;
  85.     }
  86.     dos_close( handle );
  87.  
  88.     _Com_Cprint_Output = 1;
  89.     if ( (int)_Com_Cprint_Number >= 0 )
  90.     {
  91.         _Com_Cprint_Output = 3;
  92.         com_init( _Com_Cprint_Number, 0,0,0,0,0 );
  93.     }
  94.  
  95.     return 0;
  96. }
  97.  
  98.  
  99. /**************************************************************************************************
  100. *
  101. *    MAIN( int ARGC, char *ARGV[] )
  102. *    Initial entry into this program
  103. *
  104. *    Given:
  105. *        ARGC = number of command line arguments
  106. *        ARGV -> array of pointers to the command line arguments
  107. *
  108. *    Returns:
  109. *        When its good and ready
  110. *
  111. **************************************************************************************************/
  112. main( int argc, char *argv[] )
  113. {
  114.     char    date_buffer[12], time_buffer[12];
  115.     int        line_number;
  116.  
  117.     print( "\fNet Page\nCopyright (c) April 1992, Ryu Consulting\nWritten by Rahner James\n\nLoading user info ..." );
  118.  
  119. /*
  120. ** See if they provided us with a DEF file
  121. */
  122.     if ( argc < 2 )
  123.     {
  124.         print( "\nCommand line syntax is:  net_page <door info filename> <line #>" );
  125.         exit( 3 );
  126.     }
  127.     strcpy( Def_File, argv[1] );
  128.     line_number = atoi( argv[2] );
  129.     if ( access( Def_File, 0 ) )
  130.     {
  131.         print( "\nError accessing file %s, aborting", Def_File );
  132.         exit( 1 );
  133.     }
  134.  
  135. /*
  136. ** Get the running parameters
  137. */
  138.     if ( get_globals() != 0 )
  139.     {
  140.         print( "\nError initializing globals, aborting" );
  141.         exit( 2 );
  142.     }
  143.  
  144. /*
  145. ** Say howdy to user and send the broadcast
  146. */
  147.     if ( _Com_Cprint_Output == 1 )
  148.         print( "\nPaging the sysop, please hold your horses ..." );
  149.     else
  150.         cprint( "\nPaging the sysop, please hold your horses ..." );
  151.     sprintf( Message, "%s %s: Page from %40s line %d", get_date_string(date_buffer), get_time_string(time_buffer), User_Name, line_number );
  152.     strip_char( Message, ' ', 1 );
  153.     Message[64] = 0;
  154.     broadcast_to_console( Message );
  155.     if ( _Com_Cprint_Output == 1 )
  156.     {
  157.         print( "\nPage sent.  If the sysop cares, he'll break in" );
  158.     }
  159.     else
  160.     {
  161.         cprint( "\nPage sent.  If the sysop cares, he'll break in" );
  162.         while ( com_qout(_Com_Cprint_Number) );
  163.     }
  164.     com_stop( _Com_Cprint_Number );
  165.  
  166.     exit( 0 );
  167. }
  168.  
  169.  
  170.